package cn.cuiliangpeng.basic.service.impl;

import cn.cuiliangpeng.basic.mapper.BaseMapper;
import cn.cuiliangpeng.basic.query.BaseQuery;
import cn.cuiliangpeng.basic.utils.PageList;
import cn.cuiliangpeng.basic.service.IBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
/**
 * 公共业务实现
 */
import java.util.List;
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    public List<T> findAll() {
        return baseMapper.findAll();
    }

    @Override
    public T findById(Long id) {
        return baseMapper.findById(id);
    }

    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public PageList<T> queryPage(BaseQuery query) {
        Long totals = baseMapper.queryCount(query);
        if(totals == null || totals < 1){
            return new PageList<T>();
        }
        List<T> data = baseMapper.queryData(query);
        return new PageList<T>(totals,data);
    }

    @Override
    @Transactional
    public void patch(Long[] ids) {
        baseMapper.patch(ids);
    }
}
